package com.databasedesign.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.databasedesign.dao.DormitoryLiveinDao;
import com.databasedesign.dao.StudentDao;
import com.databasedesign.pojo.po.Dormitory;
import com.databasedesign.pojo.po.DormitoryLivein;
import com.databasedesign.pojo.po.Student;
import com.databasedesign.service.DormitoryLiveinService;
import com.databasedesign.service.DormitoryService;
import com.databasedesign.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DormitoryLiveinServiceImpl extends ServiceImpl<DormitoryLiveinDao, DormitoryLivein> implements DormitoryLiveinService {
    @Autowired
    private DormitoryLiveinDao dormitoryLiveinDao;

    @Autowired
    private StudentService studentService;

    @Autowired
    private DormitoryService dormitoryService;

    @Override
    public void InsertDormitoryLivein() {
        dormitoryLiveinDao.TruncateTable();
        List<Student> GirlList = studentService.GetGirlAddress();
        List<Dormitory> GirlDormitory = dormitoryService.GetGirl();
        int i = 1;
        int m = 0;
        for(Student student : GirlList){
            Dormitory dormitory = GirlDormitory.get(m);
            dormitoryLiveinDao.Insert(dormitory.getDormitoryId(),student.getStudentId(),student.getStudentNumber(),i);
            i = i + 1;
            if (i>6){i=1;m++;}
        }


        List<Student> BoylList = studentService.GetBoyAddress();
        List<Dormitory> BoyDormitory = dormitoryService.GetBoy();
        int j = 1;
        int n = 0;
        for(Student student : BoylList){
            Dormitory dormitory = BoyDormitory.get(n);
            dormitoryLiveinDao.Insert(dormitory.getDormitoryId(),student.getStudentId(),student.getStudentNumber(),j);
            j = j + 1;
            if (j>6){j=1;n++;}
        }
    }


}
